home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / SAT / myPlatform ƒ / sPlatform.p < prev    next >
Encoding:
Text File  |  1994-07-26  |  3.0 KB  |  123 lines  |  [TEXT/PJMM]

  1. { Platform sprite, experimental faceless sprite }
  2.  
  3. unit sPlatform;
  4.  
  5. interface
  6.  
  7.     uses
  8.         SAT;
  9.  
  10.     procedure InitPlatform;
  11.     procedure SetupPlatform (me: SpritePtr);
  12.     procedure HandlePlatform (me: SpritePtr);
  13.     procedure HitPlatform (me, him: SpritePtr);
  14.  
  15. implementation
  16.  
  17.     procedure InitPlatform;
  18.         var
  19.             i: integer;
  20.     begin
  21. {The platform has no faces!}
  22.     end;
  23.  
  24.     procedure SetupPlatform (me: SpritePtr);
  25.         var
  26.             r: Rect;
  27.             pol: PolyHandle;
  28.     begin
  29.         me^.task := @HandlePlatform;
  30.         me^.hittask := @HitPlatform;
  31.  
  32.         {me^.kind := -2; {Enemy kind}
  33.         me^.face := nil; {=faceless!}
  34.         SetRect(me^.hotRect, 0, 0, 100, 16);
  35.         r := me^.hotRect;
  36.         offSetRect(r, me^.position.h, me^.position.v);
  37.         SetPort(gSAT.backScreen);
  38. {Perhaps we should SATSetPortBackScreen nowadays…}
  39. {but it works anyway - we're in no hurry here, and we don't CopyBits.}
  40.         FillRect(r, dkgray);
  41.  
  42.         pol := OpenPoly;
  43.         MoveTo(r.left, r.top);
  44.         LineTo(r.left + 5, r.top - 5);
  45.         LineTo(r.right + 5, r.top - 5);
  46.         LineTo(r.right, r.top);
  47.         LineTo(r.left, r.top);
  48.         LineTo(r.right, r.top);
  49.  
  50.         LineTo(r.right, r.bottom);
  51.         LineTo(r.right + 5, r.bottom - 5);
  52.         LineTo(r.right + 5, r.top - 5);
  53.         LineTo(r.right, r.top);
  54.  
  55.         ClosePoly;
  56.         ErasePoly(pol);
  57.         FramePoly(pol);
  58.         KillPoly(pol);
  59.  
  60.         r.top := r.top - 5;
  61.         r.right := r.right + 5;
  62.         SATBackChanged(r); {Tell SAT to draw it when appropriate}
  63.  
  64.         me^.layer := -me^.position.v;
  65.     end;
  66.  
  67.     procedure HandlePlatform (me: SpritePtr);
  68.     begin
  69.         {me^.face := nil; {Really not needed}
  70.     end;
  71.  
  72.     procedure HitPlatform;
  73.         var
  74.             mini, i, min: integer;
  75.             diff: array[1..4] of integer;
  76.     begin
  77.         if him^.Task <> @HandlePlatform then
  78.             begin
  79.                 diff[1] := -me^.hotRect2.top + (him^.hotRect2.bottom);    {TtoB}
  80.                 diff[2] := -him^.hotRect2.top + (me^.hotRect2.bottom);    {BtoT}
  81.                 diff[3] := -me^.hotRect2.left + (him^.hotRect2.right);    {LtoR}
  82.                 diff[4] := -him^.hotRect2.left + (me^.hotRect2.right);    {RtoL}
  83.                 mini := 0;
  84.                 min := 10000;
  85.                 for i := 1 to 4 do
  86.                     if min > diff[i] then
  87.                         begin
  88.                             min := diff[i];
  89.                             mini := i;
  90.                         end;
  91.                 case mini of
  92.                     1: {floor}
  93.                         begin
  94.                             him^.position.v := him^.position.v - diff[1] + 1;
  95.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  96.                             if him^.speed.v > 0 then
  97.                                 him^.speed.v := 0;
  98.                         end;
  99.                     2: {ceiling}
  100.                         begin
  101.                             him^.position.v := him^.position.v + diff[2] + 1;{me^.position.v + 17}
  102. {We don't signal here. A hit in the ceiling should just send him back down again.}
  103.                             if him^.speed.v < 0 then
  104.                                 him^.speed.v := -him^.speed.v;
  105.                         end;
  106.                     3: {left}
  107.                         begin
  108.                             him^.position.h := him^.position.h - diff[3] - 1;{me^.position.h - 32}
  109.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  110.                             if him^.speed.h > 0 then
  111.                                 him^.speed.h := -him^.speed.h;
  112.                         end;
  113.                     4: {right}
  114.                         begin
  115.                             him^.position.h := him^.position.h + diff[4] + 1;{me^.position.h + 100}
  116.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  117.                             if him^.speed.h < 0 then
  118.                                 him^.speed.h := -him^.speed.h;
  119.                         end;
  120.                 end;{case}
  121.             end; {if}
  122.     end; {HitPlatform}
  123. end.{of unit}